#define _CRT_SECURE_NO_WARNINGS 1
#include"stack.h"


void STInit(ST* pc)
{
	assert(pc);
	StackType* tmp = malloc(sizeof(StackType) * 4);
	if (tmp == NULL)
	{
		perror("malloc");
	}
	pc->a = tmp;
	pc->sz = 0;
	pc->capacity = 4;
}

void STDestory(ST* pc)
{
	assert(pc);
	free(pc->a);
	pc->a = NULL;
}

void STPush(ST* pc, int x)
{
	assert(pc);
	if (pc->sz == pc->capacity)
	{
		StackType* tmp = (StackType*)realloc(pc->a,sizeof(StackType) * pc->capacity * 2);
		if (tmp == NULL)
		{
			perror("raalloc");
		}
		pc->a = tmp;
		pc->capacity *= 2;
	}
	pc->a[pc->sz++] = x;
}

void STPop(ST* pc)
{
	assert(pc);
	pc->sz--;
}

StackType STTop(ST* pc)
{
	assert(pc);
	return pc->a[pc->sz];
}

